From: Keir Fraser Date: Mon, 6 Jul 2009 10:48:44 +0000 (+0100) Subject: xend: allow pv_ops kernel driver pci-stub to hide devices for assignment X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~13648 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22?a=commitdiff_plain;h=51dd9a1427a17dc9fdcc259a22dc5425b2ea323d;p=xen.git xend: allow pv_ops kernel driver pci-stub to hide devices for assignment pciback is used by VT-d to hide device for assigment. But in pv-ops dom0, pciback is not supported yet. Fortunately, pci-stub module is used to hide device in Linux for KVM VT-d device assignment and it's included in pv-ops dom0. So can use pci-stub to hide devices for assignment. Device must be hidden before assignment. Control panel has checks if devices can be assigned or not, and can list assignable devices via reading devices owned by pciback. This patch changes the checks, and also list assignable devices which are owned by pci-stub. Use pci-stub to hide devices, and use this patch to pass checkes in control panel, device assignemnt with VT-d works on Xen with pv-ops dom0. Signed-off-by: Weidong Han --- diff --git a/tools/python/xen/util/pci.py b/tools/python/xen/util/pci.py index b826f8ea3c..e651d5c544 100644 --- a/tools/python/xen/util/pci.py +++ b/tools/python/xen/util/pci.py @@ -33,6 +33,7 @@ SYSFS_PCI_DEV_SUBVENDOR_PATH = '/subsystem_vendor' SYSFS_PCI_DEV_SUBDEVICE_PATH = '/subsystem_device' SYSFS_PCI_DEV_CLASS_PATH = '/class' SYSFS_PCIBACK_PATH = '/bus/pci/drivers/pciback/' +SYSFS_PCISTUB_PATH = '/bus/pci/drivers/pci-stub/' LSPCI_CMD = 'lspci' @@ -450,7 +451,10 @@ def restore_pci_conf_space(pci_cfg_list): os.write(fd, dw) os.close(fd) -def find_all_devices_owned_by_pciback(): +def find_all_assignable_devices(): + ''' devices owned by pcibak or pci-stub can be directly assigned to + guest with IOMMU (VT-d or AMD IOMMU), find all these devices. + ''' sysfs_mnt = find_sysfs_mnt() pciback_path = sysfs_mnt + SYSFS_PCIBACK_PATH pci_names = os.popen('ls ' + pciback_path).read() @@ -459,6 +463,14 @@ def find_all_devices_owned_by_pciback(): for pci in pci_list: dev = PciDevice(parse_pci_name(pci)) dev_list = dev_list + [dev] + + pcistub_path = sysfs_mnt + SYSFS_PCISTUB_PATH + pci_names = os.popen('ls ' + pcistub_path).read() + pci_list = extract_the_exact_pci_names(pci_names) + for pci in pci_list: + dev = PciDevice(parse_pci_name(pci)) + dev_list = dev_list + [dev] + return dev_list def transform_list(target, src): @@ -921,10 +933,10 @@ class PciDevice: return for pci_dev in devs: dev = PciDevice(parse_pci_name(pci_dev)) - if dev.driver == 'pciback': + if dev.driver == 'pciback' or dev.driver == 'pci-stub': continue err_msg = 'pci: %s must be co-assigned to the same guest with %s' + \ - ', but it is not owned by pciback.' + ', but it is not owned by pciback or pci-stub.' raise PciDeviceAssignmentError(err_msg % (pci_dev, self.name)) def do_FLR(self): diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 40b81cf1ac..ff38009d08 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -716,7 +716,7 @@ class XendDomainInfo: except Exception, e: raise VmError("pci: failed to locate device and "+ "parse it's resources - "+str(e)) - if pci_device.driver!='pciback': + if pci_device.driver!='pciback' and pci_device.driver!='pci-stub': raise VmError(("pci: PCI Backend does not own device "+ \ "%s\n"+ \ "See the pciback.hide kernel "+ \ diff --git a/tools/python/xen/xend/XendNode.py b/tools/python/xen/xend/XendNode.py index 9cdcb13888..fb08046ab8 100644 --- a/tools/python/xen/xend/XendNode.py +++ b/tools/python/xen/xend/XendNode.py @@ -835,7 +835,7 @@ class XendNode: def pciinfo(self): # Each element of dev_list is a PciDevice - dev_list = PciUtil.find_all_devices_owned_by_pciback() + dev_list = PciUtil.find_all_assignable_devices() # Each element of devs_list is a list of PciDevice devs_list = PciUtil.check_FLR_capability(dev_list) diff --git a/tools/python/xen/xend/server/pciif.py b/tools/python/xen/xend/server/pciif.py index cb1e83b854..a4c976b7bf 100644 --- a/tools/python/xen/xend/server/pciif.py +++ b/tools/python/xen/xend/server/pciif.py @@ -224,7 +224,7 @@ class PciController(DevController): return sxpr def CheckSiblingDevices(self, domid, dev): - """ Check if all sibling devices of dev are owned by pciback + """ Check if all sibling devices of dev are owned by pciback or pci-stub """ if not self.vm.info.is_hvm(): return @@ -245,12 +245,9 @@ class PciController(DevController): #no dom0 drivers bound to sdev continue - if sdev.driver!='pciback': - raise VmError(("pci: PCI Backend does not own\n "+ \ - "sibling device %s of device %s\n"+ \ - "See the pciback.hide kernel "+ \ - "command-line parameter or\n"+ \ - "bind your slot/device to the PCI backend using sysfs" \ + if sdev.driver!='pciback' and sdev.driver!='pci-stub': + raise VmError(("pci: PCI Backend and pci-stub don't\n "+ \ + "own sibling device %s of device %s\n"\ )%(sdev.name, dev.name)) return @@ -265,13 +262,9 @@ class PciController(DevController): raise VmError("pci: failed to locate device and "+ "parse it's resources - "+str(e)) - if dev.driver!='pciback': - raise VmError(("pci: PCI Backend does not own device "+ \ - "%s\n"+ \ - "See the pciback.hide kernel "+ \ - "command-line parameter or\n"+ \ - "bind your slot/device to the PCI backend using sysfs" \ - )%(dev.name)) + if dev.driver!='pciback' and dev.driver!='pci-stub': + raise VmError(("pci: PCI Backend and pci-stub don't own "+ \ + "device %s\n") %(dev.name)) if dev.has_non_page_aligned_bar and arch.type != "ia64": raise VmError("pci: %s: non-page-aligned MMIO BAR found." % dev.name) @@ -285,7 +278,8 @@ class PciController(DevController): # if arch.type != "ia64": # dev.do_FLR() - PCIQuirk(dev) + if dev.driver == 'pciback': + PCIQuirk(dev) if not self.vm.info.is_hvm(): # Setup IOMMU device assignment @@ -437,13 +431,9 @@ class PciController(DevController): raise VmError("pci: failed to locate device and "+ "parse it's resources - "+str(e)) - if dev.driver!='pciback': - raise VmError(("pci: PCI Backend does not own device "+ \ - "%s\n"+ \ - "See the pciback.hide kernel "+ \ - "command-line parameter or\n"+ \ - "bind your slot/device to the PCI backend using sysfs" \ - )%(dev.name)) + if dev.driver!='pciback' and dev.driver!='pci-stub': + raise VmError(("pci: PCI Backend and pci-stub don't own device "+ \ + "%s\n") %(dev.name)) # Need to do FLR here before deassign device in order to terminate # DMA transaction, etc